import * as types from '../types'
const state = {
  path:'',//记录路径
  path2:'',
  menuActive:'1_01',
  navActive:'',//子tab选项
  clientWidth:document.body.clientWidth-180,
  clientHeight:document.body.clientHeight-100,
}
const actions = {
}

const getters = {
  path: state => state.path,
  path2: state => state.path2,
  menuActive:state=>state.menuActive,
  navActive:state=>state.navActive,
  clientWidth:state=>state.clientWidth,
  clientHeight:state=>state.clientHeight,
}
const mutations = {
  [types.SET_PATH](state,v){
    state.path=v
    //侧边栏选中
    let datas=[]
    window.global.menus.map(r=>{
      datas.push(r)
      if(r.submenus.length>0) datas=datas.concat(r.submenus)
    })
    for (let i of datas) {
      let res=v.split('/')
      if ((i.url)==v||res[0]==i.url){
      // if ((i.url)==v||(res[0]+'/'+res[1])==i.url){
        state.menuActive = i.id
      }
    }
  },
  [types.SET_PATH2](state,v){
    state.path2=v
  },
  setNavActive(state,v){
    state.navActive=v
  },
  [types.SET_RESIZE](state,v){
    if(v.clientHeight) state.clientHeight = v.clientHeight
    if(v.clientWidth) state.clientWidth = v.clientWidth
  }
}

export default {
  namespaced:true,
  state,
  getters,
  actions,
  mutations
}
